package com.mebs.model.inventory;

import com.mebs.model.logistics.Box;
import com.mebs.model.AttachedFile;

import javax.persistence.*;
import java.util.Set;

import org.jt.jet.util.JetUtils;

/**
 * Created by Sergey Prasolov, sap@jensentechnologies.com Date: Apr 7, 2006, 1:31:06 PM
 */
@Entity
@Table(name = "RO_PIECES")
@Inheritance(strategy = InheritanceType.JOINED)
@PrimaryKeyJoinColumn(name = "Id")
public class RelocationPiece extends Box {
    @ManyToOne(optional = false)
    @JoinColumn(name = "OrderId")
    private RelocationOrder order;

    @OneToMany(fetch = FetchType.LAZY)
    @JoinTable(name = "RO_PIECE_FILES",
        joinColumns = {@JoinColumn(name = "PieceId")},
        inverseJoinColumns = {@JoinColumn(name = "FileId")})
    private Set<AttachedFile> files;

    /**
     * Constructors
     */

    public RelocationPiece()
    {
    }

    public RelocationPiece(
        RelocationOrder order,
        Integer number,
        Double dimL,
        Double dimW,
        Double dimH,
        Integer dimUnit,
//        Double volume,
//        Integer volumeUnit,
        Double weight,
        Integer weightUnit)
    {
        super(number, dimL, dimW, dimH, dimUnit/*, volume, volumeUnit*/, weight, weightUnit);
        this.order = order;
    }

    /**
     * ********************** Getters-setters ***********************
     */
    public RelocationOrder getOrder()
    {
        return order;
    }

    public void setOrder(RelocationOrder order)
    {
        this.order = order;
    }

    public Set<AttachedFile> getFiles()
    {
        return files;
    }

    public void setFiles(Set<AttachedFile> files)
    {
        this.files = files;
    }

    @Transient
    public boolean isDeletable()
    {
        return (JetUtils.isEmpty(this.files));
    }
}
